//
//  AccountCell.m
//  iMoney
//
//  Created by VertigoSol on 9/14/08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "AccountCell.h"


@implementation AccountCell
@synthesize name, amount;

-(void)setVals:(NSString*)nname: (float)namount;
{
	amount.text = [NSString stringWithFormat:@"%.2f", namount];
	if(namount >= 0)
	{
		amount.textColor = [UIColor blueColor];
	}
	else
		amount.textColor = [UIColor redColor];
	name.text = [nname copy];
}



- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
   
	if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {		
		
		UIView *myContentView = self.contentView;
		
		self.name = [self newLabelWithPrimaryColor:[UIColor blackColor] selectedColor:[UIColor whiteColor] fontSize:18.0 bold:YES]; 
		self.name.textAlignment = UITextAlignmentLeft; // default
		[myContentView addSubview:self.name];
		[self.name release];
		
		
		self.amount = [self newLabelWithPrimaryColor:[UIColor blackColor] selectedColor:[UIColor whiteColor] fontSize:16.0 bold:YES]; 
		self.amount.textAlignment = UITextAlignmentLeft; // default
		[myContentView addSubview:self.amount];
		[self.amount release];
		
	}
	
	return self;
		

}


- (void)layoutSubviews {
	
    [super layoutSubviews];
	
	// getting the cell size
    CGRect contentRect = self.contentView.bounds;
	
	// get the X pixel spot
	CGFloat boundsX = contentRect.origin.x;
	CGRect frame;
	
	
	// In this example we will never be editing, but this illustrates the appropriate pattern
    if (!self.editing) {
	
		frame = CGRectMake(boundsX + 10, 4, 200, 30);
		self.name.frame = frame;
        
		frame = CGRectMake(boundsX + 150, 4, 100, 30);
		self.amount.frame = frame;
		
	}
	else
	{
		frame = CGRectMake(boundsX + 10, 2, 200, 30);
		self.name.frame = frame;
        
		frame = CGRectZero;
		self.amount.frame = frame;
	}
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

	[super setSelected:selected animated:animated];
}

- (UILabel *)newLabelWithPrimaryColor:(UIColor *)primaryColor selectedColor:(UIColor *)selectedColor fontSize:(CGFloat)fontSize bold:(BOOL)bold
{
	/*
	 Create and configure a label.
	 */
	
    UIFont *font;
    if (bold) {
        font = [UIFont boldSystemFontOfSize:fontSize];
    } else {
        font = [UIFont systemFontOfSize:fontSize];
    }
    
    /*
	 Views are drawn most efficiently when they are opaque and do not have a clear background, so set these defaults. 
	 To show selection properly, however, the views need to be transparent (so that the selection color shows through).  This is handled in setSelected:animated:.
	 */
	UILabel *newLabel = [[UILabel alloc] initWithFrame:CGRectZero];
	newLabel.backgroundColor = [UIColor whiteColor];
	newLabel.opaque = YES;
	newLabel.textColor = primaryColor;
	newLabel.highlightedTextColor = selectedColor;
	newLabel.font = font;
	
	return newLabel;
}

//- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
//{
//	//
//	
//}


- (void)dealloc {
   
	[name release];
	[amount release];
	[super dealloc];
}


@end
